package com.xfc.web.controller.school;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xfc.school.domain.ScItemList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xfc.common.annotation.Log;
import com.xfc.common.core.controller.BaseController;
import com.xfc.common.core.domain.AjaxResult;
import com.xfc.common.enums.BusinessType;
import com.xfc.school.domain.ScItemChangeRecord;
import com.xfc.common.utils.poi.ExcelUtil;
import com.xfc.common.core.page.TableDataInfo;
import com.xfc.school.service.IScItemChangeRecordService;
/**
 * 物品变更记录Controller
 * 
 * @author xfc
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/school/record")
public class ScItemChangeRecordController extends BaseController
{
    @Autowired
    private IScItemChangeRecordService scItemChangeRecordService;

    /**
     * 查询物品变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('school:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScItemChangeRecord scItemChangeRecord)
    {
        startPage();
        List<ScItemChangeRecord> list = scItemChangeRecordService.list(Wrappers.query(scItemChangeRecord).orderByDesc("update_time"));

        return getDataTable(list);
    }

    /**
     * 导出物品变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('school:record:export')")
    @Log(title = "物品变更记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ScItemChangeRecord scItemChangeRecord)
    {
        List<ScItemChangeRecord> list = scItemChangeRecordService.list();
        ExcelUtil<ScItemChangeRecord> util = new ExcelUtil<ScItemChangeRecord>(ScItemChangeRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取物品变更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(scItemChangeRecordService.getById(id));
    }

    /**
     * 新增物品变更记录
     */
    @PreAuthorize("@ss.hasPermi('school:record:add')")
    @Log(title = "物品变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScItemChangeRecord scItemChangeRecord)
    {
        return toAjax(scItemChangeRecordService.save(scItemChangeRecord));
    }

    /**
     * 修改物品变更记录
     */
    @PreAuthorize("@ss.hasPermi('school:record:edit')")
    @Log(title = "物品变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScItemChangeRecord scItemChangeRecord)
    {
        return toAjax(scItemChangeRecordService.updateById(scItemChangeRecord));
    }

    /**
     * 删除物品变更记录
     */
    @PreAuthorize("@ss.hasPermi('school:record:remove')")
    @Log(title = "物品变更记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids){
		List<String> list=new ArrayList<>();
    	if (ids!=null&&ids.length>0) {
            for (String id : ids) {
                list.add(id);
            }
		}
        return toAjax(scItemChangeRecordService.removeByIds(list));
    }
}
